package com.hb.trade.api.im.config;

import org.fzzn.core.cache.redis.StringRedisService;
import org.fzzn.core.component.jwt.service.RedisCacheService;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ImRedisCacheService implements RedisCacheService {

    protected final StringRedisService redisService;

    public ImRedisCacheService(StringRedisService redisService) {
        this.redisService = redisService;
    }

    @Override
    public void setDataBase(int dataBase) {
        redisService.setDataBase(dataBase);
    }

    @Override
    public String get(String key) {
        return redisService.get(key);
    }

    @Override
    public void set(String key, String value) {
        redisService.set(key, value);
    }

    /**
     * 存入缓存
     *
     * @param key
     * @param value
     * @param milliSeconds 过期时间(单位: 豪秒)
     * @return
     */
    @Override
    public void set(String key, String value, long milliSeconds) {
        redisService.set(key, value, milliSeconds, TimeUnit.MILLISECONDS);
    }

    @Override
    public void expire(String key, long milliSeconds) {
        redisService.expire(key, milliSeconds);
    }
}
